﻿Imports System.Data
Imports VSModel
Imports Cls_Common
Imports SecurityService

Partial Class Control_Formula_List
    Inherits System.Web.UI.UserControl
    Private Shared ReadOnly log As log4net.ILog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
#Region "Sub and Function"
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            'xu ly jquery khi post back
            Dim script As ScriptManager = ScriptManager.GetCurrent(Me.Page)
            If Not script Is Nothing AndAlso script.IsInAsyncPostBack Then
                ScriptManager.RegisterStartupScript(Me.Page, Me.Page.GetType, "jqueryEnable", "ajaxJquery()", True)
            Else
                Me.Page.ClientScript.RegisterStartupScript(Me.Page.GetType(), "jqueryEnable", String.Concat("Sys.Application.add_load(function(){", "ajaxJquery()", "});"), True)
            End If
            getYear()
            getWeek()
            getStatus()
            getFomulaType()
            If Not Request.QueryString("FormulaTypeId") Is Nothing Then
                drlType.SelectedValue = CInt(Request.QueryString("FormulaTypeId"))
            End If
            BindToGrid(1, txtTitle.Text.Trim(), drlType.SelectedValue, drlStatus.SelectedValue, txtNguoitao.Text.Trim, txtCreated.Text.Trim, ddlSSMOriginal.SelectedValue, ddlYear.SelectedValue, ddlWeek.SelectedValue)
            btnDelete.Attributes.Add("onclick", "return confirmMultiDelete('" & btnDelete.ClientID & "');")
        End If
    End Sub

    Private Sub BindToGrid(Optional ByVal iPage As Integer = 1, Optional ByVal strTitle As String = "", Optional ByVal intType As Integer = 0, Optional ByVal intStatus As Integer = 0, Optional ByVal strCreator As String = "", Optional ByVal strCreated As String = "", Optional ByVal intOriginal As Integer = -1, Optional ByVal intYear As Integer = 0, Optional ByVal intWeek As Integer = 0)
        Using data As New VSEntities
            Dim arrSearch() As String = {iPage.ToString, strTitle, intType.ToString, intStatus.ToString, strCreator, strCreated, intOriginal, intYear, intWeek}

            ViewState("search") = arrSearch
            'So ban ghi muon the hien tren trang
            Dim intPag_Size As Int32 = drpPage_Size.SelectedValue
            Dim intOrderBy As Int32 = ddlSort.SelectedValue

            Dim startWeek As Date
            If intYear <> 0 And intWeek <> 0 Then
                startWeek = GetFirstDayOfWeek(intYear, intWeek)
            Else
                startWeek = #1/1/1900#
            End If
            Dim p As List(Of uspFormulaSelectAll_Result) = data.uspFormulaSelectAll(IIf(String.IsNullOrEmpty(txtTitle.Text.Trim) = True, Nothing, txtTitle.Text.Trim), IIf(intType = 0, Nothing, intType), IIf(intStatus = 0, Nothing, intStatus), IIf(String.IsNullOrEmpty(strCreator) = True, Nothing, strCreator), IIf(String.IsNullOrEmpty(strCreated) = True, Nothing, StringToDate(strCreated)), intOriginal, IIf(startWeek = #1/1/1900#, Nothing, startWeek), IIf(startWeek = #1/1/1900#, Nothing, startWeek.AddDays(6)), intOrderBy, iPage, intPag_Size).ToList

            'Tong so ban ghi
            If p.Count > 0 Then
                hidCount.Value = p.FirstOrDefault.Total()
                Create_Pager(hidCount.Value, iPage, intPag_Size, 10)
            Else
                hidCount.Value = 0
                With rptPage
                    .DataSource = Nothing
                    .DataBind()
                End With
            End If
            Dim strKey_Name() As String = {"Id", "Title", "Created", "Modified", "StatusId", "FormulaTypeId", "FormulaTypeName"}
            With grdShow
                .DataKeyNames = strKey_Name
                .DataSource = p
                .DataBind()
            End With
            lblTotal.Text = "Hiển thị " + (((iPage - 1) * intPag_Size) + 1).ToString + " đến " + (((iPage - 1) * intPag_Size) + grdShow.Rows.Count).ToString + " trong tổng số " + hidCount.Value.ToString + " bản ghi."
        End Using
    End Sub
    Protected Sub getFomulaType()
        Using data As New VSEntities
            Dim p = (From q In data.FormulaTypes Select q.Id, q.Title).ToList
            drlType.DataValueField = "Id"
            drlType.DataTextField = "Title"
            drlType.DataSource = p
            drlType.DataBind()
            drlType.Items.Add(New ListItem("---Tất cả---", 0))
            drlType.SelectedValue = 0
        End Using
    End Sub
    Protected Sub getStatus()
        Using data As New VSEntities
            Dim p = (From q In data.Status Select q).ToList
            drlStatus.DataValueField = "StatusId"
            drlStatus.DataTextField = "Title"
            drlStatus.DataSource = p
            drlStatus.DataBind()
            drlStatus.Items.Add(New ListItem("---Tất cả---", 0))
            drlStatus.SelectedValue = 0
        End Using
    End Sub
    Protected Sub getYear()
        ddlYear.DataSource = Enumerable.Range(2001, 15)
        ddlYear.DataBind()
        ddlYear.Items.Add(New ListItem("---Tất cả---", 0))
        ddlYear.SelectedValue = 0 'Year(Now.Date)
    End Sub
    Protected Sub getWeek()

        ddlWeek.DataSource = Enumerable.Range(1, 52)
        ddlWeek.DataBind()
        ddlWeek.Items.Add(New ListItem("---Tất cả---", 0))
        ' Dim curWeek As Integer = (Now.DayOfYear / 7)
        ddlWeek.SelectedValue = 0 'curWeek
    End Sub
    Protected Function GetFirstDayOfWeek(ByVal year As Integer, ByVal weekNumber As Integer) As DateTime
        Return GetFirstDayOfWeek(year, weekNumber, System.Threading.Thread.CurrentThread.CurrentCulture)
    End Function
    Public Function GetFirstDayOfWeek(ByVal year As Integer, ByVal weekNumber As Integer, ByVal culture As System.Globalization.CultureInfo) As DateTime
        Dim calendar As System.Globalization.Calendar = culture.Calendar
        Dim firstOfYear As New DateTime(year, 1, 1, calendar)
        Dim targetDay As DateTime = calendar.AddWeeks(firstOfYear, weekNumber)
        Dim firstDayOfWeek As DayOfWeek = culture.DateTimeFormat.FirstDayOfWeek

        While targetDay.DayOfWeek <> firstDayOfWeek
            targetDay = targetDay.AddDays(-1)
        End While

        Return targetDay
    End Function

    Sub Create_Pager(ByVal Total_Record As Integer, ByVal Page_Index As Integer, ByVal Page_Size As Integer, ByVal Page2Show As Integer)
        Dim TotalPage As Integer = IIf((Total_Record Mod Page_Size) = 0, Total_Record / Page_Size, Total_Record \ Page_Size + 1)
        'lu lai tong so ban ghi
        hidIndex_page.Value = TotalPage
        'gan lai curPage de set active
        hidCur_Page.Value = Page_Index
        'generate ra left page
        Dim cPageGenerate_left As IEnumerable(Of Integer)
        If Page_Index <= Page2Show Then
            cPageGenerate_left = Enumerable.Range(1, Page_Index)
        Else
            cPageGenerate_left = Enumerable.Range(Page_Index - Page2Show, Page2Show)
        End If
        'generate ra right page
        Dim cPageGenerate_Right As IEnumerable(Of Integer)
        If Page_Index + Page2Show <= TotalPage Then
            cPageGenerate_Right = Enumerable.Range(Page_Index, Page2Show + 1)
        Else
            cPageGenerate_Right = Enumerable.Range(Page_Index, TotalPage - Page_Index + 1)
        End If
        'union 2 range va bind to Grid
        With rptPage
            .DataSource = cPageGenerate_left.Union(cPageGenerate_Right)
            .DataBind()
        End With
    End Sub
    Protected Sub rptPage_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptPage.ItemDataBound
        Dim lnkTitle As LinkButton
        lnkTitle = e.Item.FindControl("lnkTitle")
        If e.Item.DataItem = hidCur_Page.Value Then
            lnkTitle.Text = "<span class='current'>" & e.Item.DataItem & "</span>"
        Else
            lnkTitle.Text = "<span>" & e.Item.DataItem & "</span>"
        End If
        lnkTitle.ToolTip = e.Item.DataItem
    End Sub
    Protected Sub lnkTitle_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim lnkTile As LinkButton = CType(sender, LinkButton)
        Dim arrSearch() As String
        arrSearch = ViewState("search")
        BindToGrid(CInt(lnkTile.ToolTip.ToString), _
                   arrSearch(1).ToString, _
                   CInt(arrSearch(2).ToString), _
                   CInt(arrSearch(3).ToString), _
                   arrSearch(4), _
                   arrSearch(5), _
                   CInt(arrSearch(6)), _
                   CInt(arrSearch(7).ToString), _
                   CInt(arrSearch(8).ToString))
        lnkLast.Enabled = True
        lnkFirst.Enabled = True
        If CInt(lnkTile.ToolTip) = hidIndex_page.Value Then
            lnkLast.Enabled = False
        ElseIf CInt(lnkTile.ToolTip) = 1 Then
            lnkFirst.Enabled = False
        End If
    End Sub
    Protected Sub lnkFirst_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFirst.Click
        If hidCur_Page.Value > 1 Then
            hidCur_Page.Value = hidCur_Page.Value - 1
        End If
        Dim arrSearch() As String
        arrSearch = ViewState("search")
        BindToGrid(hidCur_Page.Value, arrSearch(1).ToString, CInt(arrSearch(2).ToString), CInt(arrSearch(3).ToString), arrSearch(4), arrSearch(5).ToString, CInt(arrSearch(6)), CInt(arrSearch(7).ToString), CInt(arrSearch(8).ToString))
    End Sub
    Protected Sub lnkLast_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkLast.Click
        hidCur_Page.Value = hidCur_Page.Value + 1
        Dim arrSearch() As String
        arrSearch = ViewState("search")
        BindToGrid(hidCur_Page.Value, arrSearch(1).ToString, CInt(arrSearch(2).ToString), CInt(arrSearch(3).ToString), arrSearch(4), arrSearch(5).ToString, CInt(arrSearch(6)), CInt(arrSearch(7).ToString), CInt(arrSearch(8).ToString))
    End Sub
#End Region
#Region "Event for control"
    Protected Sub chkAll_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
        For Each itm As GridViewRow In grdShow.Rows
            Dim chkItem As CheckBox = CType(itm.Cells(0).FindControl("chkItem"), CheckBox)
            If chkItem.Enabled = True Then
                chkItem.Checked = CType(sender, CheckBox).Checked
            End If
        Next
    End Sub
    Protected Sub lnkbtnDelete_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim intId As Integer
        Dim strLogName As String = ""
        Using data As New VSEntities
            intId = grdShow.DataKeys(hidID.Value)("Id").ToString
            Dim q = (From p In data.Formulae Where p.Id = intId Select p).FirstOrDefault
            Try
                data.Formulae.DeleteObject(q)
                data.SaveChanges()
                Insert_App_Log("Delete Formula:" & q.Title & "", Function_Name.Formula, Audit_Type.Delete, Request.ServerVariables("REMOTE_ADDR"), Session("UserName"))
                Excute_Javascript("Alertbox('Xóa dữ liệu thành công.');", Me.Page, True)
            Catch ex As Exception
                log4net.Config.XmlConfigurator.Configure()
                log.Error("Error error " & AddTabSpace(1) & Session("Username") & AddTabSpace(1) & "IP:" & GetIPAddress(), ex)
                Excute_Javascript("Alertbox('Xóa thất bại.');", Me.Page, True)
            End Try
            Dim arrSearch() As String
            arrSearch = ViewState("search")
            BindToGrid(1, arrSearch(1).ToString, CInt(arrSearch(2).ToString), CInt(arrSearch(3).ToString), arrSearch(4), arrSearch(5).ToString, CInt(arrSearch(6)), CInt(arrSearch(7).ToString), CInt(arrSearch(8).ToString))
        End Using
    End Sub
    Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Dim intId As Integer = 0
        Dim intCount As Integer
        Dim intTotal As Integer
        Dim strLogName As String = ""
        Using data As New VSEntities
            Try
                For Each item As GridViewRow In grdShow.Rows
                    Dim chkItem As New CheckBox
                    chkItem = CType(item.FindControl("chkItem"), CheckBox)
                    If chkItem.Checked Then
                        intTotal += 1
                        intId = grdShow.DataKeys(item.RowIndex)("Id").ToString
                        Dim q = (From p In data.Formulae Where p.Id = intId Select p).FirstOrDefault
                        strLogName = strLogName & "," & q.Title.ToString
                        Try
                            data.Formulae.DeleteObject(q)
                            data.SaveChanges()
                            intCount += 1
                        Catch ex As Exception
                        End Try
                    End If
                Next
                If intCount > 0 Then
                    Insert_App_Log("Delete Formula:" & strLogName & "", Function_Name.Formula, Audit_Type.Delete, Request.ServerVariables("REMOTE_ADDR"), Session("UserName"))
                    Excute_Javascript("Alertbox('Xóa dữ liệu thành công. " & intCount.ToString & " /" & intTotal.ToString & " record.');", Me.Page, True)
                Else
                    Excute_Javascript("Alertbox('Xóa thất bại.');", Me.Page, True)
                End If
            Catch ex As Exception
                log4net.Config.XmlConfigurator.Configure()
                log.Error("Error error " & AddTabSpace(1) & Session("Username") & AddTabSpace(1) & "IP:" & GetIPAddress(), ex)
                Excute_Javascript("Alertbox('Xóa thất bại.');", Me.Page, True)
            End Try
        End Using
        Dim arrSearch() As String
        arrSearch = ViewState("search")
        BindToGrid(1, arrSearch(1).ToString, CInt(arrSearch(2).ToString), CInt(arrSearch(3).ToString), arrSearch(4), arrSearch(5).ToString, CInt(arrSearch(6)), CInt(arrSearch(7).ToString), CInt(arrSearch(8).ToString))

    End Sub
    Protected Sub grdShow_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles grdShow.PageIndexChanging
        grdShow.PageIndex = e.NewPageIndex
        BindToGrid()
    End Sub
    Protected Sub grdShow_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdShow.RowDataBound
        If e.Row.RowIndex >= 0 Then
            Dim status As Integer = grdShow.DataKeys(e.Row.RowIndex)("StatusId")
            Dim lnkbtnDelete As LinkButton = CType(e.Row.FindControl("lnkbtnDelete"), LinkButton)
            Dim lblSTT As Label = CType(e.Row.FindControl("lblSTT"), Label)
            lblSTT.Text = CInt(drpPage_Size.SelectedValue) * (CInt(hidCur_Page.Value) - 1).ToString + e.Row.RowIndex + 1
            Dim hplTypeName As HyperLink = CType(e.Row.FindControl("hplTypeName"), HyperLink)
            hplTypeName.Text = grdShow.DataKeys(e.Row.RowIndex)("FormulaTypeName").ToString
            hplTypeName.NavigateUrl = "../../Page/Formula/List.aspx?FormulaTypeId=" & grdShow.DataKeys(e.Row.RowIndex)("FormulaTypeId").ToString

            Dim ScriptManager As System.Web.UI.ScriptManager = System.Web.UI.ScriptManager.GetCurrent(Me.Page)
            ScriptManager.RegisterAsyncPostBackControl(lnkbtnDelete)
            Dim chkItem As CheckBox = CType(e.Row.FindControl("chkItem"), CheckBox)
            'Permission
            If HasPermission(Function_Name.Formula, Session("RoleID"), status, Audit_Type.Delete) = True Then
                lnkbtnDelete.Attributes.Add("onclick", "return ComfirmDialog('" + drpMessage.Items(0).Text + "', 0,'" + lnkbtnDelete.ClientID + "','" + e.Row.RowIndex.ToString + "',1);")
            Else
                lnkbtnDelete.Enabled = False
                chkItem.Enabled = False
            End If
            Dim hplEdit As HyperLink = CType(e.Row.FindControl("hplEdit"), HyperLink)
            'Permission
            hplEdit.Enabled = HasPermission(Function_Name.Formula, Session("RoleID"), status, Audit_Type.Edit)
            hplEdit.NavigateUrl = "../../Page/Formula/Edit.aspx?Id=" & grdShow.DataKeys(e.Row.RowIndex)("Id").ToString
            Dim hplTitle As HyperLink = CType(e.Row.FindControl("hplTitle"), HyperLink)
            'Permission
            hplTitle.Enabled = HasPermission(Function_Name.Formula, Session("RoleID"), status, Audit_Type.ViewContent)
            hplTitle.NavigateUrl = "../../Page/Formula/Detail.aspx?Id=" & grdShow.DataKeys(e.Row.RowIndex)("Id").ToString
            hplTitle.Text = grdShow.DataKeys(e.Row.RowIndex)("Title").ToString
        End If
    End Sub
    Protected Sub drpPage_Size_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles drpPage_Size.SelectedIndexChanged
        Dim arrSearch() As String
        arrSearch = ViewState("search")
        BindToGrid(1, arrSearch(1).ToString, CInt(arrSearch(2).ToString), CInt(arrSearch(3).ToString), arrSearch(4), arrSearch(5).ToString, CInt(arrSearch(6)), CInt(arrSearch(7).ToString), CInt(arrSearch(8).ToString))

    End Sub

    Protected Sub btnPublish_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPublish.Click
        Dim StringId As String = ""
        Dim intTotal As Integer
        Using data As New VSEntities
            For Each item As GridViewRow In grdShow.Rows
                Dim chkItem As New CheckBox
                chkItem = CType(item.FindControl("chkItem"), CheckBox)
                If chkItem.Checked Then
                    intTotal += 1
                    StringId += grdShow.DataKeys(item.RowIndex)("Id").ToString & ","
                    'Write Code here
                End If
            Next
            Response.Redirect("../../Page/Formula/ActionList.aspx?Id=" & StringId & "&NStatusId=3")
        End Using
    End Sub
    Protected Sub btnExportToExcel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExportToExcel.Click
        Dim strCol As String() = {"STT", "Tiêu đề", "Loại", "Ngày tạo", "Người tạo", "Ngày cập nhật cuối", "Người cập nhật cuối", "Ngày xuất bản", "Trạng thái", "Url", "Lượt xem"}
        Using data As New VSEntities
            Dim startWeek As Date = Nothing
            If ddlYear.SelectedValue <> 0 And ddlWeek.SelectedValue <> 0 Then
                startWeek = GetFirstDayOfWeek(ddlYear.SelectedValue, ddlWeek.SelectedValue)
            Else
                startWeek = #1/1/1900#
            End If

            Dim EndWeek As Date = Nothing
            If (startWeek = Nothing) Then
                EndWeek = #1/1/1900#
            Else
                EndWeek = startWeek.AddDays(6)
            End If

            Dim CreateDeate As Date = Nothing
            If String.IsNullOrEmpty(txtCreated.Text.Trim) = True Then
                CreateDeate = #1/1/1900#
            Else
                CreateDeate = StringToDate(txtCreated.Text.Trim)
            End If

            Dim p As List(Of uspFormulaSelectAll_Result) = data.uspFormulaSelectAll(IIf(txtTitle.Text.Trim = "", Nothing, txtTitle.Text.Trim) _
                                                                                    , IIf(drlType.SelectedValue = "0", Nothing, CInt(drlType.SelectedValue)) _
                                                                                    , IIf(drlStatus.SelectedValue = "0", Nothing, CInt(drlStatus.SelectedValue)) _
                                                                                    , IIf(txtNguoitao.Text.Trim = "", Nothing, txtNguoitao.Text.Trim) _
                                                                                    , IIf(CreateDeate = #1/1/1900#, Nothing, CreateDeate) _
                                                                                    , ddlSSMOriginal.SelectedValue _
                                                                                    , IIf(startWeek = #1/1/1900#, Nothing, startWeek) _
                                                                                    , IIf(startWeek = #1/1/1900#, Nothing, EndWeek) _
                                                                                    , ddlSort.SelectedValue _
                                                                                    , 1 _
                                                                                    , data.Contents.Count _
                                                                                    ).ToList
            Dim x = p.Select(Function(c) New With {c.RowNum, c.Title, c.FormulaTypeName, c.Created, c.Creator, c.Modified, c.Modifier, c.PublishedDate, c.StatusName, c.Id, c.QueryString, c.Viewed, c.FormulaTypeQueryString}).ToList

            'Export to excel
            Response.ContentType = "application/csv"
            Response.Charset = ""
            Response.AddHeader("Content-Disposition", "attachment;filename=ExportToExcel.xls")
            Response.ContentEncoding = Encoding.Unicode
            Response.BinaryWrite(Encoding.Unicode.GetPreamble())

            Dim sb As StringBuilder = New StringBuilder()

            For i As Integer = 0 To strCol.Length - 1
                sb.Append(strCol(i))
                If (i < strCol.Length - 1) Then
                    sb.Append(vbTab)
                End If
            Next

            Response.Write(sb.ToString() & vbCrLf)
            Response.Flush()

            For i As Integer = 0 To x.Count - 1
                sb = New StringBuilder()
                sb.Append((i + 1).ToString())
                sb.Append(vbTab)

                sb.Append(x(i).Title.ToString().Replace("""", "'").Replace("""", "'"))
                sb.Append(vbTab)

                sb.Append(x(i).FormulaTypeName)
                sb.Append(vbTab)

                sb.Append(x(i).Created.ToString())
                sb.Append(vbTab)

                If (Not x(i).Creator Is Nothing AndAlso x(i).Creator.ToString <> "") Then
                    sb.Append(x(i).Creator.ToString())
                Else
                    sb.Append("")
                End If
                sb.Append(vbTab)

                sb.Append(IIf(IsDBNull(x(i).Modified) = True, "", x(i).Modified.ToString()))
                sb.Append(vbTab)

                If (Not x(i).Modifier Is Nothing AndAlso x(i).Modifier.ToString <> "") Then
                    sb.Append(x(i).Modifier.ToString())
                Else
                    sb.Append("")
                End If
                sb.Append(vbTab)

                If (Not x(i).PublishedDate Is Nothing AndAlso x(i).PublishedDate.ToString <> "") Then
                    sb.Append(x(i).PublishedDate.ToString())
                Else
                    sb.Append("")
                End If
                sb.Append(vbTab)

                sb.Append(x(i).StatusName.ToString())
                sb.Append(vbTab)

                sb.Append("http://sucsongmoi.net/84-nau-gi-hom-nay/" & x(i).FormulaTypeQueryString.ToString & "/" & x(i).QueryString.ToString & "-" & x(i).Id.ToString & ".html")
                sb.Append(vbTab)

                sb.Append(IIf(IsNothing(x(i)) = True, 0, x(i).Viewed).ToString())
                Response.Write(sb.ToString() & vbCrLf)
                Response.Flush()
            Next

            Response.End()
        End Using
    End Sub

#End Region
#Region "Search"
    Protected Sub btnFilter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFilter.Click
       
        BindToGrid(1, txtTitle.Text.Trim(), drlType.SelectedValue, drlStatus.SelectedValue, txtNguoitao.Text.Trim, txtCreated.Text.Trim, ddlSSMOriginal.SelectedValue, ddlYear.SelectedValue, ddlWeek.SelectedValue)
    End Sub
    Protected Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear.Click
        txtTitle.Text = ""
        txtNguoitao.Text = ""
        drlStatus.SelectedValue = 0
        drlType.SelectedValue = 0
        txtCreated.Text = ""
        ddlYear.SelectedValue = 0
        ddlWeek.SelectedValue = 0
        ddlSSMOriginal.SelectedValue = -1
     
        BindToGrid(1, txtTitle.Text.Trim(), drlType.SelectedValue, drlStatus.SelectedValue, txtNguoitao.Text.Trim, txtCreated.Text.Trim, ddlSSMOriginal.SelectedValue, ddlYear.SelectedValue, ddlWeek.SelectedValue)
    End Sub
#End Region


End Class
